$(function() {
	var shopData = {
		data: [
			{
				"premises_name":"泰安市奥林匹克花园小区",
				"building_num":"01",
				"unit":"01",
				"room_num":"101",
				"receivable_amount":'80',
				"status":"未缴纳",
				"remarks":"请尽快缴费"
			},
			{
				"premises_name":"华新山水居",
				"building_num":"02",
				"unit":"02",
				"room_num":"202",
				"receivable_amount":'50',
				"status":"已缴纳",
				"remarks":"已缴费"
			},
		]
	};
	function shopModal() {
		var self = this;
		self.defaults = {
			activeIndex: 0,
			isAdd: false,
			isAllcheck: false,
			isCancle: true,
			initData: {
				premises_name:"华新房地产",
				building_num:"00",
				unit:"00",
				room_num:"000",
				receivable_amount:"50",
				status:"caonibaba",
				remarks:"无"
			}
		}
		self.listData = ko.observableArray(shopData.data);
		self.line = ko.observable(self.defaults.initData);
		self.lineClick = function(data, e) {
			isHavePayButton(data);
			var lineData = $.extend({}, self.defaults.initData, data);
			self.line(lineData);
			var index = $(e.target).closest("li").index();
			self.defaults.activeIndex = index;
			self.defaults.isAdd = false;
		}
		
	}
	ko.applyBindings(new shopModal());
	//验证可否进行支付
	$('#submit').click(function(){
		if(!$('#receivable_amount').val()){
			UM.alert({
			    title: '未正确生成费用,无法缴纳！',
			    btnText: ["", "确定"],
			});
			return;
		}
		alert('可以提交支付');
		//to do 提交物业费的缴纳
		
	});
});
//如果客户的缴费状态为未缴费和无需缴纳，则将这张单据中的提交缴费按钮hidden掉，否则则取消hidden
function isHavePayButton(data) {
	var sta = data.status;
	//console.log(sta);
	if(sta == '已缴纳' || sta == '无需缴纳'){
		$('#submit').hide();
	}else{
		$('#submit').show();
	}
}
